from __future__ import annotations

from .schema import TableBase

from loguru import logger

def get_logger():
    return logger


def check_table_exist(conn, table_name) -> bool:
    sql = f"""SELECT EXISTS 
        (
            SELECT 1 
            FROM pg_tables
            WHERE tablename = '{table_name}'
        );"""
    with conn:
        with conn.cursor() as cursor:
            cursor.execute(sql)
            result = cursor.fetchone()
            return result[0]

def check_table_exist_async(conn, table_name, obj) -> bool:
    sql = f"""SELECT EXISTS 
        (
            SELECT 1 
            FROM pg_tables
            WHERE tablename = '{table_name}'
        );"""
    with conn:
        with conn.cursor() as cursor:
            cursor.execute(sql)
            obj._wait(conn)

            result = cursor.fetchone()
            return result[0]
